package com.jdbc.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestInsert {
    // 执行一次后，再次执行，报错 主键不能重复
    //Duplicate entry '4' for key 'users.PRIMARY'
    public static void main(String[] args) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        int i = 0;
        try {
            conn = JdbcUtils.getConnection();//获取数据库连接
            st = conn.createStatement();
            String sql = "INSERT INTO `users`(`id`,`NAME`,`PASSWORD`,`email`,`birthday`) " +
                    "VALUES('4','dasima','123456','dasima@qq.com','1980-11-23')";
            i = st.executeUpdate(sql);
            if(i>0){
                System.out.println("插入成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(conn,st,rs);
        }
    }
}
